 /***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.15
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   循环指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "forinstructionview.h"
#include "ui_forinstructionview.h"
#include "../../programView/programview.h"


ForInstructionView::ForInstructionView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::ForInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
}

void ForInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->note_GBox->hide();
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void ForInstructionView::updateView()
{
    if(1 == selectHeadFlag)
    {
        ui->loopHead_radioButton->setChecked(true);
    }
    if(1 == selectTailFlag)
    {
        ui->loopTail_radioButton->setChecked(true);
    }

    ui->rRegister_lineEdit->setText(rIndex);

    if(0 == dealValueTypeFlag)
    {
        ui->TO_radioButton->setChecked(true);
    }
    else
    {
        ui->DOWNTO_radioButton->setChecked(true);
    }

    ui->initialValue_comboBox->setCurrentIndex(initialValueTypeIndex - 1);
    ui->initialValue_lineEdit->setText(initialData);
    ui->targetValue_comboBox->setCurrentIndex(targetValueTypeIndex - 1);
    ui->targetValue_lineEdit->setText(targetData);

    ui->note_lineEdit->setText(note);
}

void ForInstructionView::getInput()
{
    rIndex = ui->rRegister_lineEdit->text();

    initialValueTypeIndex = ui->initialValue_comboBox->currentIndex() + 1;
    targetValueTypeIndex = ui->targetValue_comboBox->currentIndex() + 1;

    initialData = ui->initialValue_lineEdit->text();
    targetData= ui->targetValue_lineEdit->text();

    note = ui->note_lineEdit->text();
}

void ForInstructionView::on_loopHead_radioButton_clicked()
{
    emit selectForHead();
}

void ForInstructionView::on_loopTail_radioButton_clicked()
{
    emit selectFortail();
}

void ForInstructionView::on_TO_radioButton_clicked()
{
    emit selectToType();
}

void ForInstructionView::on_DOWNTO_radioButton_clicked()
{
    emit selectDownType();
}

void ForInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNote();
}

void ForInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void ForInstructionView::on_save_Btn_clicked()
{
    getInput();

    emit finishEditInstruction();
    emit saveInstructionHead(forInstructionHead);
}

void ForInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/forViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}
